//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "PlotPatternsParameters.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  PlotPatternsParameters* plotPatternsParameters = NULL;
  String*                 namefileOut            = NULL;

  if (argc < 3) {
    
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./PlotPatternConditionalProbability <Out File>";
    cout <<                                    " <Header of graph>";
    cout <<                                    " <AA, CH, PH, SS, MT> <Filename with compact Patterns>";
    cout <<                                    " [AA, CH, PH, SS, MT] [Filename with compact Patterns]....";
    cout << endl;
    
    return 0;
    
  }
  else {
    
    plotPatternsParameters = new PlotPatternsParameters ();
    
    namefileOut            = new String(argv[1]);
    plotPatternsParameters->Title()->In(argv[2]);
    
    for (int i = 3; i < argc; i++) {
      
      Pratt2PatternsByCATH* newPratt2PatternsByCATH = new Pratt2PatternsByCATH ();

      if      (!strcmp(argv[i], "AA")) plotPatternsParameters->PatternsListType()->Add(new String ("Amino Acid Patterns"));
      else if (!strcmp(argv[i], "CH")) plotPatternsParameters->PatternsListType()->Add(new String ("Chemical AA Class Patterns"));
      else if (!strcmp(argv[i], "PH")) plotPatternsParameters->PatternsListType()->Add(new String ("Physical AA Class Patterns"));
      else if (!strcmp(argv[i], "SS")) plotPatternsParameters->PatternsListType()->Add(new String ("Secondary Structure Patterns"));
      else if (!strcmp(argv[i], "MT")) plotPatternsParameters->PatternsListType()->Add(new String ("Meta-Structure Patterns"));
      else                             plotPatternsParameters->PatternsListType()->Add(new String ("Amino Acid Patterns"));
      
      cout << "                   Type of Patterns : " << argv[i++] << endl;
      
      newPratt2PatternsByCATH->Namefile(new String(argv[i]));
      plotPatternsParameters->PatternsList()->Add(newPratt2PatternsByCATH);
      
      cout << "     Filename with compact Patterns : " << argv[i] << endl;
      
    }
    
    cout << "                    Header of graph : " << argv[2] << endl;
    cout << " Filename Out with compact Patterns : " << argv[1] << endl;
    cout << "---------------------------------------------------------------------------------" << endl;
    
  }
  
  bool condFail = false;
  
  plotPatternsParameters->FilenameOut(namefileOut);

  plotPatternsParameters->PatternsList()->SetInitial();
  while (plotPatternsParameters->PatternsList()->SetNext()) {
    
    if (!plotPatternsParameters->PatternsList()->GetCurrent()->LoadData()) {
      cout << "Error Loading the files with patterns" << endl;
      condFail = true;
      break;
    }
    
  }
  
  if (!condFail)
    plotPatternsParameters->PlotProbBelongGroupByContainPattern();

  cout << "Finished..." << endl << "Good Bye" << endl;
  
  if (plotPatternsParameters) delete plotPatternsParameters;
  if (namefileOut)            delete namefileOut;
  
  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

